<!-- 设备列表 1: 性诱测报列表  2 虫情监测列表  3 监控设备列表  4 小气候设备列表  -->

<template>
	<view class="page">
		<!-- token && isLogin -->
		<template v-if="token && isLogin">
			<template>
				<view class="h90 m-b2">
					<view class="fix-wrap">
						<view class="dev-tab">
							<!-- #ifndef APP-PLUS -->
							<picker mode="region" @change="selectArea">
								<view class="area-ctrl">
									<view class="city-name split f-s30 f-wb">{{ city.name || '城市' }}</view>
									<view class="iconfont f-s20">&#xe623;</view>
								</view>
							</picker>
							<view class="change-btn" @click="showPopup('show', 'isChangeType')">
								<view class="select-data f-s30">{{ device_info.name }}</view>
								<view class="iconfont f-s20">&#xe623;</view>
							</view>
							<!-- #endif -->

							<!-- #ifdef APP-PLUS -->
							<view class="change-btn" @click="showCity">
								<view class="select-data f-s30">{{ city.name || '城市' }}</view>
								<view class="iconfont f-s20">&#xe623;</view>
							</view>
							<view class="change-btn" @click="showPicker">
								<view class="select-data f-s30">{{ device_info.name }}</view>
								<view class="iconfont f-s20">&#xe623;</view>
							</view>
							<!-- #endif -->
						</view>
						<view class="search-ctrl">
							<view class="search-bar">
								<view class="iconfont f-s34">&#xe663;</view>
								<input type="text" confirm-type="search" v-model="params.keywork" class="sc-inp"
									placeholder="输入设备地址/设备编号" @confirm="searchScan" />
							</view>
						</view>
					</view>
				</view>
				<view class="body">
					<template v-if="!loadingState.default">
						<template v-if="list.data.length > 0">
							<view class="list-wrap">
								<view class="tool-item" v-for="(item, index) in list.data" :key="index">
									<template v-if="device_info.type != 20">
										<navigator :url="'/package_common/detail/detail?number=' + item.number"
											hover-class="none" class="info-wrap">
											<view class="pic">
												<image v-if="item.file_path" :src="img_path + item.file_path + '&type=1'"
													mode="widthFix"></image>
												<image v-else :src="WEB_HOST + '/images/map/' + device_info.type + '.png'"
													mode="widthFix"></image>
											</view>
											<view class="info">
												<view class="name">
													{{ item.NAME || item.device_name || item.cameraName || item.name || item.dev_name }}
												</view>
												<view class="text number">
													<view class="label">设备型号：</view>
													<view class="content split-line">
														{{ item.dev_number || item.model || item.encoderUuid || '--' }}
													</view>
												</view>
												<view class="text address">
													<view class="label">安装地址：</view>
													<view class="content split-line">
														<template v-if="item.address">
															{{ item.address || '不详' }}
														</template>
														<template v-else>
															{{ item.remark || '不详' }}
														</template>
													</view>
												</view>
											</view>
										</navigator>
									</template>


									<!-- 性诱测报 -->
									<template v-if="device_info.type == 1">
										<view class="btn-wrap">
											<navigator :url="
													'/package_common/attractant/attractant?type=detail&dev_id=' +
														item.id +
														'&dev_name=' +
														item.NAME +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												引诱剂
											</navigator>
											<navigator :url="
													'/package_xingyou/weather_data/weather_data?dev_name=' +
														item.NAME +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												气象数据
											</navigator>
											<navigator :url="
													'/package_xingyou/pest_data/pest_data?type=data&dev_name=' +
														item.NAME +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												虫害数据
											</navigator>
										</view>
									</template>

									<!-- 虫情测报 -->
									<template v-if="device_info.type == 2">
										<view class="btn-wrap">
											<navigator :url="
													'/package_pests/dev_manage/dev_manage?dev_name=' +
														item.device_name +
														'&dev_num=' +
														item.dev_number +
														'&typeid=' +
														device_info.typeid +
														'&seting_type=' +
														item.seting_type
												" class="btn" hover-class="none">
												设备管理
											</navigator>
											<navigator :url="
													'/package_pests/pic_data/pic_data?dev_name=' +
														item.device_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												识别图像
											</navigator>
											<navigator :url="
													'/package_pests/pest_data/pest_data?type=data&dev_name=' +
														item.device_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												虫害数据
											</navigator>
										</view>
									</template>

									<!-- 监控设备 -->
									<template v-if="device_info.type == 3">

										<view class="btn-wrap">
											<navigator v-if="device_info.typeid == 12" :url="
													'/package_jiankong/pic_data/pic_data?dev_name=' +
														item.cameraName +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												苗情图像
											</navigator>
											<template v-if="device_info.typeid == 11">
												<template v-if="item.fwq_type==1">
													<navigator
														:url="'/package_jiankong/hk_jiankong/hk_jiankong?dev_name=' + item.cameraName + '&dev_id=' + item.cameraUuid + '&dev_type=' + device_info.type + '&onlinestatus=' + item.onLineStatus + '&typeid=' + device_info.typeid+ '&fwq_type=' + item.fwq_type"
														class="btn" hover-class="none">查看监控</navigator>
												</template>
												<template v-else>
													<navigator :url="
													'/package_jiankong/jiankong/jiankong?dev_name=' +
														item.cameraName +
														'&dev_id=' +
														item.cameraUuid +
														'&dev_type=' +
														device_info.type +
														'&onlinestatus=' +
														item.onLineStatus +
														'&typeid=' +
														device_info.typeid+
														'&fwq_type=' +
														item.fwq_type
												" class="btn" hover-class="none">
														查看监控
													</navigator>
												</template>
											</template>

										</view>
									</template>

									<!-- 小气候 -->
									<template v-if="device_info.type == 4">
										<view class="btn-wrap">
											<navigator :url="
													'/package_xiaoqihou/data_data/data_data?dev_name=' +
														item.dev_name +
														'&dev_model=' +
														item.dev_number +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												查看数据
											</navigator>
										</view>
									</template>
									<!-- 高空测报灯 -->
									<template v-if="device_info.type == 6">
										<view class="btn-wrap">
											<navigator :url="
													'/package_shachongdeng/gaokong_manage/gaokong_manage?dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												设备管理
											</navigator>
											<navigator :url="
													'/package_xiaoqihou/data_data/data_data?dev_name=' +
														item.dev_name +
														'&dev_model=' +
														item.dev_number +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												查看数据
											</navigator>
										</view>
									</template>

									<!-- 天牛测报 -->
									<template v-if="device_info.type == 8">
										<view class="btn-wrap">
											<navigator :url="
													'/package_common/attractant/attractant?type=detail&dev_id=' +
														item.id +
														'&dev_name=' +
														item.dev_name +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												引诱剂
											</navigator>
											<navigator :url="
													'/package_tianniu/pest_data/pest_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												虫害数据
											</navigator>
										</view>
									</template>

									<!-- 全景设备 -->
									<template v-if="device_info.type == 9">
										<view class="btn-wrap">
											<navigator :url="
													'/package_quanjin/data_data/data_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												全景图像
											</navigator>
										</view>
									</template>

									<!-- 显示屏 -->
									<template v-if="device_info.type == 10">
										<view class="btn-wrap">
											<navigator :url="
													'/package_xianshiping/data_data/data_data?dev_name=' +
														item.dev_name +
														'&dev_number=' +
														item.dev_number +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												查看数据
											</navigator>
										</view>
									</template>

									<!-- 自动清虫杀虫灯 -->
									<template v-if="device_info.type == 11">
										<view class="btn-wrap">
											<navigator :url="
													'/package_shachongdeng/dev_manage/dev_manage?dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												设备管理
											</navigator>
											<navigator :url="
													'/package_shachongdeng/pest_data/pest_data?dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												清虫状况
											</navigator>
										</view>
									</template>

									<!-- 实蝇测报 -->
									<template v-if="device_info.type == 12">
										<view class="btn-wrap">
											<navigator :url="
													'/package_common/attractant/attractant?type=detail&dev_id=' +
														item.id +
														'&dev_name=' +
														item.dev_name +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												引诱剂
											</navigator>
											<navigator :url="
													'/package_shiying/weather_data/weather_data?dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												气象数据
											</navigator>
											<navigator :url="
													'/package_shiying/pest_data/pest_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												虫害数据
											</navigator>
										</view>
									</template>

									<!-- 孢子仪 -->
									<template v-if="device_info.type == 13">
										<view class="btn-wrap">
											<navigator :url="
													'/package_baoziyi/pest_data/pest_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid+
														'&device_type='+item.device_type
												" class="btn" hover-class="none">
												数据分析
											</navigator>
											<navigator :url="
													'/package_baoziyi/photo_data/photo_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid+
														'&device_type='+item.device_type
												" class="btn" hover-class="none">
												图片列表
											</navigator>
											<navigator :url="
													'/package_baoziyi/table_data/table_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid+
														'&device_type='+item.device_type
												" class="btn" hover-class="none">
												数据列表
											</navigator>
										</view>
									</template>

									<!-- 性诱拍照 -->
									<template v-if="device_info.type == 14">
										<view class="btn-wrap">
											<!-- <navigator
												:url="'/package_xingyoupaizhao/home/home?type=data&dev_name='+item.dev_name+'&dev_id='+item.id+'&dev_type='+device_info.type+'&typeid='+device_info.typeid"
												class="btn" hover-class="none">数据列表</navigator>
											<navigator -->
											<navigator :url="
													'/package_common/attractant/attractant?type=detail&dev_id=' +
														item.id +
														'&dev_name=' +
														item.dev_name +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												引诱剂
											</navigator>
											<navigator :url="
													'/package_xingyoupaizhao/photo_data/photo_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												图片列表
											</navigator>
											<navigator :url="
													'/package_xingyoupaizhao/drug_manage/drug_manage?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												虫害数据
											</navigator>
										</view>
									</template>

									<!-- 墒情监测 -->
									<template v-if="device_info.type == 15">
										<view class="btn-wrap">
											<navigator :url="
													'/package_shangqing/pest_data/pest_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid+
														'&type=' +
														item.type
												" class="btn" hover-class="none">
												数据分析
											</navigator>
											<navigator :url="
													'/package_shangqing/table_data/table_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid +
														'&type=' +
														item.type
												" class="btn" hover-class="none">
												数据列表
											</navigator>
										</view>
									</template>

									<!-- YRY-联网杀虫灯 -->
									<template v-if="device_info.type == 17">
										<view class="btn-wrap">
											<navigator :url="
													'/package_yryshachongdeng/dev_manage/dev_manage?dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												设备管理
											</navigator>
											<navigator :url="
													'/package_yryshachongdeng/echart_data/echart_data?dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												数据分析
											</navigator>
											<navigator :url="
													'/package_yryshachongdeng/pest_data/pest_data?dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
												" class="btn" hover-class="none">
												清虫状况
											</navigator>
										</view>
									</template>

									<!-- 病情监测仪 -->
									<template v-if="device_info.type == 18">
										<view class="btn-wrap">
											<navigator :url="
													'/package_bqjcy/photo_data/photo_data?type=data&dev_name=' +
														item.dev_name +
														'&dev_id=' +
														item.id +
														'&dev_type=' +
														device_info.type +
														'&typeid=' +
														device_info.typeid
											" class="btn" hover-class="none">
												图片列表
											</navigator>
										</view>
									</template>

									<!-- 黄板 -->
									<template v-if="device_info.type == 19">
										<view class="btn-wrap">
											<navigator :url="
												'/package_huangban/dev_manage/dev_manage?dev_name=' +
													item.device_name +
													'&dev_num=' +
													item.dev_number +
													'&typeid=' +
													device_info.typeid
											" class="btn" hover-class="none">
												设备管理
											</navigator>
											<navigator :url="
												'/package_huangban/pic_data/pic_data?dev_name=' +
													item.device_name +
													'&dev_id=' +
													item.id +
													'&dev_type=' +
													device_info.type +
													'&typeid=' +
													device_info.typeid
											" class="btn" hover-class="none">
												识别图像
											</navigator>
											<navigator :url="
												'/package_huangban/pest_data/pest_data?type=data&dev_name=' +
													item.device_name +
													'&dev_id=' +
													item.id +
													'&dev_type=' +
													device_info.type +
													'&typeid=' +
													device_info.typeid
											" class="btn" hover-class="none">
												虫害数据
											</navigator>
										</view>
									</template>

									<!-- 智能瓷盘 -->
									<template v-if="device_info.type == 20">
										<navigator :url="'/package_zhinengcipan/detail/detail?number=' + item.sb_number2"
											hover-class="none" class="info-wrap">
											<view class="pic">
												<image v-if="item.file_path" :src="img_path + item.file_path + '&type=1'" mode="widthFix"></image>
												<image v-else :src="WEB_HOST + '/images/map/' + device_info.type + '.png'" mode="widthFix"></image>
											</view>
											<view class="info">
												<view class="name">
													{{item.device_number}}
												</view>
												<view class="text number">
													<view class="label">设备编号：</view>
													<view class="content split-line">
														{{ item.device_number || '--' }}
													</view>
												</view>
												<view class="text address">
													<view class="label">安装地址：</view>
													<view class="content split-line">
														<template v-if="item.address">
															{{ item.address || '不详' }}
														</template>
														<template v-else>
															{{ item.remark || '不详' }}
														</template>
													</view>
												</view>
											</view>
										</navigator>
										<view class="btn-wrap">
											<!-- <navigator :url="
												'/package_zhinengcipan/search-data/search-data?type=data&dev_name=' +
													item.device_name +
													'&dev_id=' +
													item.id +
													'&dev_type=' +
													device_info.type +
													'&typeid=' +
													device_info.typeid
											" class="btn" hover-class="none">
												设备管理
											</navigator> -->
											<navigator :url="'/package_zhinengcipan/search-data/search-data'" class="btn" hover-class="none">
												数据查看
											</navigator>
										</view>
									</template>


									<!-- 智能电源控制器 -->
									<template v-if="device_info.type == 21">
										<view class="btn-wrap">
											<view @click="toPath(item)" class="btn" hover-class="none">
												设备管理
											</view>
										</view>
									</template>

									<!-- 智能灌溉 -->
									<template v-if="device_info.type == 22">
										<view class="btn-wrap">
											<view @click="toPath(item)" class="btn" hover-class="none">
												设备管理
											</view>
										</view>
									</template>

								</view>
							</view>
							<loading :loadingState="loadingState"></loading>
						</template>
						<empty v-else>
							<view slot="msg">暂无相关设备</view>
						</empty>
					</template>
					<template v-else>
						<loading :loadingState="loadingState"></loading>
					</template>
				</view>
			</template>
		</template>

		<view v-if="flag.isFullPage" class="full-fix-page">
			<!-- APP最后一个change事件触发不了？ item-column 加border-bottom 才行？ -->
			<template v-if="flag.isChangeType">
				<view class="picker-bottom-wrap">
					<view class="hd">
						<view class="cancle" @click="showPopup('hide')">取消</view>
						<view class="confirm" @click="comfirmType">确定</view>
					</view>
					<picker-view indicator-class="indicatorClass" class="picker-view-wrap row-2" :value="changeType"
						@change="changeDevType">
						<picker-view-column class="item-column">
							<view class="item" v-for="(item, index) in device.list" :key="index" style="">
								{{ item.name }}
							</view>
						</picker-view-column>
						<picker-view-column class="item-column">
							<view class="item" v-for="(item, index) in device.child" :key="index">{{ item.name }}</view>
						</picker-view-column>
					</picker-view>
				</view>
			</template>
			<!-- // APP-PLUS -->
			<template v-if="flag.isChangeCity">
				<view class="picker-bottom-wrap">
					<view class="hd">
						<view class="cancle" @click="showPopup('hide')">取消</view>
						<view class="confirm" @click="selectCity">确定</view>
					</view>
					<picker-view indicator-class="indicatorClass" class="picker-view-wrap row-2" :value="changeCityType"
						@change="changeCity">
						<picker-view-column class="item-column">
							<view class="item" v-for="(item, index) in cities.provinceList" :key="index">{{ item.name }}
							</view>
						</picker-view-column>
						<picker-view-column class="item-column">
							<view class="item" v-for="(item, index) in cities.cityList" :key="index">{{ item.name }}
							</view>
						</picker-view-column>
						<picker-view-column class="item-column">
							<view class="item" v-for="(item, index) in cities.districtList" :key="index">{{ item.name }}
							</view>
						</picker-view-column>
					</picker-view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	import loading from '@/components/loading-more.vue';
	import empty from '@/components/empty.vue';
	import {
		WEB_HOST
	} from '@/config.js';
	export default {
		name: 'name',
		data() {
			return {
				token: uni.getStorageSync('token'),
				appid: getApp().globalData.appid,
				userInfo: uni.getStorageSync('userInfo'),
				isLogin: false,
				device_info: {
					type: '',
					name: '',
					typeid: '',
					list: [],
					sub: []
				},
				device: {},
				changeType: [],
				flag: {
					isFullPage: false,
					isChangeType: false
				},
				loginStateUpdate: false,
				loadingState: {
					default: true,
					loading: false,
					completed: false
				},
				params: {
					limit: 10,
					page: 1,
					keywork: ''
				},
				city: {
					name: '',
					adcode: ''
				},
				list: {
					all: [],
					data: [],
					disable: [],
					number: [],
					result: []
				},
				cities: {
					provinceList: [],
					cityList: [],
					districtList: []
				},
				changeCityType: [0, 0, 0],
				// list: {
				// 	total: 0,
				// 	data: [],

				// },
				img_path: getApp().globalData.image_path,
				WEB_HOST: WEB_HOST
			};
		},
		async onLoad(params) {
			console.log(params);

			this.changeType = params.changetype.split('-');
			this.device_info.type = params.dev_type;
			this.device_info.name = params.dev_name;
			this.device_info.typeid = params.typeid;

			if (this.token) {
				this.isLogin = await this.$loginState('check');
				if (this.isLogin) {
					this.device.list = await this.getDeviceType();
					if (this.changeType[0] != '') {
						if (this.device.list[this.changeType[0]].has_dev && this.device.list[this.changeType[0]]
							.has_dev.length > 0) {
							this.device.child = this.device.list[this.changeType[0]].has_dev;
						}
					}
					this.getDeviceList();
				} else {
					this.isLogin = await this.$loginState('reset');
				}
			}

			// #ifdef APP-PLUS
			uni.$on('comfirmType', data => {
				console.log('comfirm', data);
				this.changeType = data;
				this.comfirmType();
			});
			uni.$on('updateArea', data => {
				this.city.name = data.area.split(' ')[data.cityIndex];
				this.city.adcode = data.cityCode;
				this.dataInit();
				this.getDeviceList();
			});
			// #endif
		},
		async onShow() {
			// 登录状态更新 重新获取token 等值
			if (this.loginStateUpdate) {
				this.token = uni.getStorageSync('token');
				this.userInfo = uni.getStorageSync('userInfo');
				this.isLogin = true;
				this.loginStateUpdate = false;
				this.device.list = await this.getDeviceType();
				console.log('----', this.device.list);
				if (this.changeType[0] != '') {
					if (this.device.list[this.changeType[0]].has_dev && this.device.list[this.changeType[0]].has_dev
						.length > 0) {
						this.device.child = this.device.list[this.changeType[0]].has_dev;
					}
				}
				this.getDeviceList();
			}

			if (!this.token && !this.isLogin) {
				this.isLogin = await this.$loginState('reset');
			}
		},
		onReachBottom() {
			if (this.loadingState.completed) {
				this.params.page = 0;
				return false;
			} else {
				this.params.page++;
				this.getDeviceList();
			}
		},
		methods: {
			dataInit: function() {
				this.list.data = [];
				this.params.page = 1;
				this.params.key = '';
				this.loadingState.default = true;
				this.loadingState.loading = false;
				this.loadingState.completed = false;
			},

			toPath(item) {
				if (this.device_info.type == 21) {
					uni.navigateTo({
						url: `/package_zhinengdianyuan/dev_manage/dev_manage?dev_id=${item.id}&dev_name=${item.device_name}`,
					})
				} else if (this.device_info.type == 22) {
					uni.navigateTo({
						url: `/package_zhinengguangai/dev_manage/dev_manage?dev_id=${item.id}&dev_name=${item.device_name}`,

					})
				}
			},

			showCity() {
				// #ifdef APP-PLUS
				uni.$emit('resetting', {
					changeCityType: this.changeCityType
				});
				uni.getSubNVueById('select_city').show();
				// #endif
				// this.showPopup('show', 'isChangeCity');
				// this.getCities(true);
			},

			showPicker() {
				let subNvue = uni.getSubNVueById('dev_picker');
				console.log(subNvue);
				console.log('切换设备传入nvue', {
					...this.device,
					data: this.device.list,
					changeType: this.changeType
				});
				uni.$emit('dev_picker', {
					...this.device,
					data: this.device.list,
					changeType: this.changeType
				});
				subNvue.show();
			},

			async getCities(flag) {
				let prores;
				if (flag) {
					try {
						prores = await this.$api.tool_api.getCities({
							adcode: 'china',
							areaName: ''
						});
						this.cities.provinceList = prores.data.data.filter((item, index, self) => self.findIndex(x => x
							.adcode === item.adcode) === index);
					} catch (e) {
						//TODO handle the exception
						console.log('proerr', e);
					}
				}
				try {
					// console.log(this.cities.provinceList[this.changeCityType[0]], this.changeCityType);
					let cres = await this.$api.tool_api.getCities({
						adcode: this.cities.provinceList[this.changeCityType[0]].adcode,
						areaName: 'province'
					});
					let dres = await this.$api.tool_api.getCities({
						adcode: cres.data.data[this.changeCityType[1]].adcode,
						areaName: 'city'
					});

					// console.log('province: ', cres);
					this.cities.cityList = cres.data.data;
					this.cities.districtList = dres.data.data;
				} catch (e) {
					//TODO handle the exception
					console.log('cderr', e);
				}
			},

			changeCity(e) {
				// console.log(e.detail.value);
				// console.log(this.changeCityType.join().toString(), e.detail.value.join.toString());
				if (this.changeCityType.join().toString() != e.detail.value.join.toString()) {
					if (this.changeCityType[0] != e.detail.value[0]) {
						this.changeCityType = [e.detail.value[0], 0, 0];
					} else if (this.changeCityType[1] != e.detail.value[1]) {
						this.changeCityType = [e.detail.value[0], e.detail.value[1], 0];
					} else {
						this.changeCityType = e.detail.value;
					}
					this.getCities();
				}
			},

			selectCity() {
				this.city.adcode = this.cities['cityList'][this.changeCityType[1]].adcode;
				this.city.name = this.cities['cityList'][this.changeCityType[1]].name;
				this.dataInit();
				this.getDeviceList();
				this.showPopup('hide');
			},

			// 获取设备类型
			getDeviceType: async function() {
				let res = await this.$api.tool_api.getDevTypeCount({
					appid: this.appid,
					token: this.token,
					user_id: this.userInfo.uid
				});
				if (res.data.ret == 1000) {
					let data = [];
					res.data.data.forEach(item => {
						if (item.child.length > 0) {
							let has_dev = [];
							item.child.forEach(subitem => {
								if (subitem.count > 0) {
									has_dev.push(subitem);
									item.has_dev = has_dev;
								}
							});
						}
						if ((item.has_dev && item.has_dev.length > 0) || item.count > 0) {
							data.push(item);
						}
					});
					return data;
				}
			},

			// 切换设备类型
			changeDevType: function(e) {
				console.log(e, e.detail.value);
				if (this.changeType[0] != e.detail.value[0]) {
					this.changeType = [e.detail.value[0], 0];
				} else {
					this.changeType = e.detail.value;
				}
				if (this.device.list[this.changeType[0]].child.length > 0) {
					this.device.child = this.device.list[this.changeType[0]].has_dev;
				} else {
					this.device.child = [];
				}
				// console.log(this.changeType,e.detail.value);
			},

			// 确定设备类型
			comfirmType: function() {
				if (this.device.list[this.changeType[0]].has_dev && this.device.list[this.changeType[0]].has_dev
					.length > 0) {
					this.device_info.type = this.device.list[this.changeType[0]].has_dev[this.changeType[1]].number;
					this.device_info.typeid = this.device.list[this.changeType[0]].has_dev[this.changeType[1]].id;
					this.device_info.name = this.device.list[this.changeType[0]].has_dev[this.changeType[1]].name;
				} else {
					this.device_info.type = this.device.list[this.changeType[0]].number;
					this.device_info.typeid = this.device.list[this.changeType[0]].id;
					this.device_info.name = this.device.list[this.changeType[0]].name;
				}
				this.dataInit();
				this.getDeviceList();
				this.showPopup('hide');
			},

			// 获取设备列表
			getDeviceList: async function() {
				if (this.device_info.type == 20) {
					let res = await this.$api.zncp_api.getDevList({
						appid: this.appid,
						token: this.token,
						user_id: this.userInfo.uid,
						page: this.params.page,
						limit: this.params.limit,
						keyword: this.params.keywork
					}).finally(() => {
						this.loadingState.default = false;
						this.loadingState.loading = false;
					});
					if (res.data.ret == 0) {
						this.list.total = res.data.data.count;
						this.list.data = this.list.data.concat(res.data.data.list);
						if (res.data.data.list.length < this.params.limit) {
							this.loadingState.completed = true;
						} else {
							this.loadingState.loading = true;
						}
					}
				}
				// else if (this.device_info.type == 15) {
				// 	let res = await this.$api.tool_api.sq_alllist({
				// 		appid: this.appid,
				// 		token: this.token,
				// 		device_type: this.device_info.type,
				// 		user_id: this.userInfo.uid,
				// 		// page: this.params.page,
				// 		// limit: this.params.limit,
				// 		// keywork: this.params.keywork,
				// 		// adcode: this.city.adcode,
				// 		// typeid: this.device_info.typeid
				// 	}).finally(() => {
				// 		this.loadingState.default = false;
				// 		this.loadingState.loading = false;
				// 	});
				// 	console.log('设备列表', res);
				// 	if (res.data.ret == 1000) {
				// 		this.list.data = this.list.data.concat(res.data.data);
				// 		this.list.total = res.data.data.total;
				// 		if (res.data.data.length < this.params.limit) {
				// 			this.loadingState.completed = true;
				// 		} else {
				// 			this.loadingState.loading = true;
				// 		}
				// 	} else if (res.data.ret == 1002) {
				// 		this.loadingState.completed = true;
				// 	} else if (res.data.ret == 1004) {
				// 		this.loadingState.completed = false;
				// 	}
				// } 
				else {
					let res = await this.$api.tool_api.getDeviceList({
						appid: this.appid,
						token: this.token,
						device_type: this.device_info.type,
						user_id: this.userInfo.uid,
						page: this.params.page,
						limit: this.params.limit,
						keywork: this.params.keywork,
						adcode: this.city.adcode,
						typeid: this.device_info.typeid
					}).finally(() => {
						this.loadingState.default = false;
						this.loadingState.loading = false;
					});
					console.log('设备列表', res);
					if (res.data.ret == 1000) {
						this.list.data = this.list.data.concat(res.data.data);
						this.list.total = res.data.data.total;
						if (res.data.data.length < this.params.limit) {
							this.loadingState.completed = true;
						} else {
							this.loadingState.loading = true;
						}
					} else if (res.data.ret == 1002) {
						this.loadingState.completed = true;
					} else if (res.data.ret == 1004) {
						this.loadingState.completed = false;
					}
				}
			},

			searchScan: function(e) {
				this.dataInit();
				this.getDeviceList();
			},

			selectArea: function(e) {
				this.city.name = e.detail.value[1];
				this.city.adcode = e.detail.code[2];
				this.dataInit();
				this.getDeviceList();
			},

			mapGo: function(lat, lng, name, address) {
				uni.openLocation({
					latitude: parseFloat(lat),
					longitude: parseFloat(lng),
					name: name,
					address: address
				});
			},

			// 显示弹窗
			showPopup: function(t, n) {
				if (t == 'show') {
					this.flag.isFullPage = true;
					this.flag[n] = true;
				} else if (t == 'hide') {
					for (let i in this.flag) {
						this.flag[i] = false;
					}
				}
			}
		},
		components: {
			loading,
			empty
		},
		computed: {},
		watch: {}
	};
</script>

<style lang="less">
	.dev-tab {
		display: flex;
		align-items: center;
		padding: 0 20rpx;

		picker {
			margin-right: 20rpx;
		}
	}

	.area-ctrl {
		picker {
			height: 32px;
			display: flex;
			align-items: center;
		}

		.city-name {
			width: auto;
		}

		.iconfont {
			color: #666;
		}
	}

	.tool-item {
		padding: 20rpx;
		margin-bottom: 20rpx;
		background: #fff;

		.info-wrap {
			display: flex;

			.pic {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 20%;
				height: 150rpx;
				border-radius: 10rpx;
				margin-right: 20rpx;
				overflow: hidden;
				flex-shrink: 0;

				image {
					border-radius: 10rpx;
				}
			}

			.info {
				flex-grow: 2;

				.name {
					margin-bottom: 8rpx;
					font-size: 30rpx;
					font-weight: bold;
				}

				.number {
					margin-bottom: 8rpx;
					color: #666;
					font-size: 26rpx;
				}

				.text {
					display: flex;
					flex-wrap: wrap;

					.label {
						flex-shrink: 0;
					}

					.content {
						max-width: 75%;
						flex-grow: 2;
					}

					color: #666;
					font-size: 26rpx;
				}
			}
		}

		.btn-wrap {
			display: flex;
			justify-content: flex-end;
			padding-top: 20rpx;
			margin-top: 20rpx;
			border-top: 2rpx solid #e5e5e5;

			.btn {
				// width: 120rpx;
				padding: 0.2rpx 8rpx;
				text-align: center;
				margin-left: 20rpx;
				border: 2rpx solid #0085ff;
				border-radius: 8rpx;
				font-size: 28rpx;
				color: #0085ff;
			}

			.not-btn {
				padding: 0.2rpx 10rpx;
				text-align: center;
				margin-left: 20rpx;
				border: 2rpx solid #0085ff;
				border-radius: 8rpx;
				font-size: 28rpx;
				color: #0085ff;
			}
		}
	}

	.empty-wrap {
		margin-top: 30rpx;
	}
</style>